home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / headers / gworld.h < prev    next >
C/C++ Source or Header  |  1995-09-29  |  3KB  |  100 lines

  1. #pragma once
  2. //
  3. // 941006: testing this code for the first time in a long time. It appears
  4. // that one needs an instance of a 'window' or a 'fullscreen' before one
  5. // can create a 'gworld'. If one does:
  6. //
  7. // gworld  earth;
  8. // window broken;
  9. //
  10. // the Mac crashes inside a 'ShowWindow' call in window:: window
  11. // I don't have time to study this in full, but I suspect that 'gworld::gworld'
  12. // somehow is buggy. Alternatively there is a bug in the System (possibly only
  13. // in system 7.5) which precludes the use of GWorlds without the use of windows.
  14. // It also might be a bug in the Think Debugger (7.0.4), since an application
  15. // I wrote to test this hypothesis did not hang.
  16. //
  17. class gworld : public port
  18. {
  19.     public:
  20.         //
  21.         // the first constructor is especially made for creating a backing-store
  22.         // to blit to the port specified.
  23.         //
  24.         gworld( int breedte, int hoogte, int diepte, port &original);
  25.  
  26.         gworld( int breedte = 320, int hoogte = 200, int diepte = 8, CTabHandle cTable = nil);
  27.         ~gworld();
  28.  
  29.         int diepte() const;
  30.  
  31.         void fill_random() const;
  32.         //
  33.         // two_bit_merge only works on a gworld of depth 2,
  34.         // and must receive two parameters of depth 1.
  35.         // (I should device subclasses for this, but I don't have time to do that)
  36.         //
  37.         void two_bit_merge( const gworld &left, const gworld &right) const;
  38.         //
  39.         // dump and load do not do extensive error checking
  40.         //
  41.         OSErr dump( short defile) const;
  42.         OSErr load( short defile) const;
  43.  
  44.     private:
  45.         int de_diepte;
  46.         
  47.         static unsigned short extendChar( const unsigned char theChar);
  48.         static const unsigned short extensions[ 256];
  49. };
  50.  
  51. inline int gworld::diepte() const
  52. {
  53.     return de_diepte;
  54. }
  55. //
  56. // This routine was bootstrapped from a slower 4-bit-at-a-time version
  57. // with the following program:
  58. //
  59. //    void main( int argc, char *argv[])
  60. //    {
  61. //        argc = ccommand( &argv);        // for THINK C
  62. //        for( int i = 0; i < 256; i++)
  63. //        {
  64. //            unsigned short result = extendCharSlow( i);
  65. //            printf( "0x%04X", result);
  66. //            if( (i % 8) == 7)
  67. //            {
  68. //                printf( ",\n");
  69. //            } else {
  70. //                printf( ", ");
  71. //            }
  72. //        }
  73. //    }
  74. //
  75. //    unsigned short extendCharSlow( const unsigned char theChar)
  76. //    {
  77. //        static const unsigned short extensions[ 16] =
  78. //        {
  79. //            0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F,
  80. //            0xC0, 0xC3, 0xCC, 0xCF, 0xF0, 0xF3, 0xFC, 0xFF
  81. //        };
  82. //        return (extensions[ theChar >> 4] << 8) + extensions[ theChar & 0x0F];
  83. //    }
  84. //
  85. // Converting to a 16-bit-at-a-time version is deemed impractical.
  86. // 941116: We could, of course do this at runtime with a static member,
  87. // and a funtion which fills the large table at startup. It only would be
  88. // a 64K table of unsigned longs, or 256K.
  89. // Before embarking on this voyage one would have to check that making
  90. // 'two_bit_merge' faster by a factor of two would improve the program. The
  91. // current version of 'StereoMovie' is fast enough for our purposes, and that
  92. // check has never been made, so we do not yet use such a large buffer.
  93. // Also, a processor cache smaller than 256K might make use of such a large
  94. // table slower than expected.
  95. //
  96. inline unsigned short gworld::extendChar( const unsigned char theChar)
  97. {
  98.     return extensions[ theChar];
  99. }
  100.